
package cn.zniot.so.application.constant;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.configuration.Configuration;

import cn.zniot.so.transport.ServerType;

/**
 * 全局常量定义
 */
public class Constants {

    public static String MAX_ECT_ALERT = "the user name or password error";

    public static String MIN_VBV_ALERT = "congratulations on your landing successful";

    public static String USER_REGISTERSUCCESS = "congratulations on your registration";

    public static String USER_REGISTERED = "the user has registered";

    public static String USERLOST = "user name does not exist";

    public static String DEFAUT_VALUE = "Fir";

    public static final String ID_HEAD = "Rec";

    public static int TIME_OUT = 30;

    public static int REPLY_WAIT_COUNT = 5;

    public static int GET_SESSION_WAIT_COUNT = 5;

    public static int GET_SESSION_WAIT = 5;

    public static int CHECK_TIME = 30;// 系统初始化后会被配置文件中的"checktime"属性值覆盖，即覆盖为120s

    public static byte[] HEART_BEAT_DOWN = new byte[] {// 服务器发给客户端的心跳(下行)
            (byte) 0xAC, (byte) 0xBB, (byte) 0xAF, (byte) 0xEA, (byte) 0xFF
    };

    // AC BB AF EA 0F 00 00 00 00 EE E6 FA
    public static byte[] CLIENT_DOWN = new byte[] {// 服务器发给客户端的下线通知
            (byte) 0xAC, (byte) 0xBB, (byte) 0xAF, (byte) 0xEA, (byte) 0x0F, 0x00, 0x00, 0x00,
            0x00, (byte) 0xEE, (byte) 0xE6, (byte) 0xFA
    };

    /**
     * 有客户端给服务器建立连接的时候发给他的报文
     */
    //AC BB AF EA F0 00 00 00 00 EE E6 FA
    public static byte[] TRYLINK = new byte[] {
            (byte) 0xAC, (byte) 0xBB, (byte) 0xAF, (byte) 0xEA, (byte) 0xF0,
            0x00, 0x00, 0x00, 0x00, (byte) 0xEE, (byte) 0xE6, (byte) 0xFA
    };
    public static final String HEART_BEAT_UP = "%"; // 客户端发给服务器的心跳(上行)
    public static final String OK = "OK"; // 给盒子发指令前，握手成功返回"OK"
    public static final String SINGE_YES = "是";
    public static final String SINGE_NO = "否";
    public static final String FAIL_CONNECT = "B"; // Zniot连接失败，原因为车或者没启动
    public static final String SLEEP_SEND_COMMAND = "M";
    public static final String NO_DATA = "手机";
    public static String BOXRATE = "盒子";
    public static long BATCH_UPLOAD_THREAD_MINUTE = 2000; // 批处理上传Zniot数据间隔分钟数
    public static long THREAD_MINUTE = 10000; // 计算线程开始休眠10秒钟
    public static float BATCH_UPLOAD_Zniot_MINUTE = 10f; // 批处理上传Zniot数据频率为10秒钟

    private Constants() {

    }

    /**
     * 客户端ID标识
     */
    public static String UID = "mda";

    /**
     * IO处理线程数（服务端）
     */
    // public static int THREADNUM_IO_SERVER =
    // Runtime.getRuntime().availableProcessors() + 1;
    public static int THREADNUM_IO_SERVER = 6;

    /**
     * 业务逻辑处理线程数（服务端）
     */
    public static int THREADNUM_LOGIC_SERVER = 3;

    /**
     * IO处理线程数（客户端）
     */
    public static int THREADNUM_IO_CLIENT = 1;

    /**
     * 业务逻辑处理线程数（客户端）
     */
    public static int THREADNUM_LOGIC_CLIENT = 1;

    /**
     * MD服务监听端口
     */
    public static int DOWNFILEPORT = 50000;

    /**
     * MD服务监听端口
     */
    public static int BOXPORT = 50000;

    /**
     * MD服务监听端口
     */
    public static int MDA_PORT_SMS = 50000;

    /**
     * 内部管理命令监听器
     */
    public static int MGR_PORT = 9002;

    /**
     * 命令执行监听IP
     */
    public static String CMD_IP;

    /**
     * 命令执行监听端口
     */
    public static int CMD_PORT;

    /**
     * RMI监听端口
     */
    public static int RMI_PORT;

    /**
     * 监听服务器类型
     */
    public static ServerType TYPE_SERVER_TCP = null;

    /**
     * 车机与中心协议转换器类名
     */
    public static String CLASSNAME_PROTOCOLCODEC = null;

    /**
     * 协议转换器名称
     */
    public static String PROTOCOL_NAME = "protocolName";

    /**
     * 协议转换器版本号
     */
    public static String PROTOCOL_VERSION = "V1.0";

    /**
     * 系统根目录
     */
    public static String HOME_DIR = ".";

    /**
     * 心跳间隔时长
     */
    public static Long HEARTBEAT;

    /**
     * 数据库驱动
     */
    public static String DB_DRIVER = null;

    /**
     * 数据库SID
     */
    public static String DB_URL = null;

    /**
     * 用户名
     */
    public static String USER = null;

    /**
     * 密码
     */
    public static String PASSWD = null;

    /**
     * 初始化连接数
     */
    public static int DB_INITPOOL_SIZE = 1;

    /**
     * 最大连接数
     */
    public static int DB_MAXPOOL_SIZE = 3;

    /**
     * 默认值
     */
    public static int DEFAUTE_VALUE = -65535;
    /**
     * AHG报文类型
     */
    public static String AHG_PACKET = "AHG";
    public static int REPLY_WAIT = 2;

    public static Map<String, String> FAULT_CODE_MAP = new HashMap<String, String>();

    public static String DOWNLOADPATH = "";

    /**
     * 初始化属性
     */
    public static void initProperties(Configuration config) {
        UID = config.getString("uid.value");
        TYPE_SERVER_TCP = ServerType.getServerType(config.getString("monitor.tcpvalue"));
        DOWNFILEPORT = config.getInt("port.external.downfilePort");
        BOXPORT = config.getInt("port.external.boxPort");
        MDA_PORT_SMS = config.getInt("port.external.smsvalue");
        MGR_PORT = config.getInt("port.inner.value");
        CMD_PORT = config.getInt("port.command.value");
        CMD_IP = config.getString("port.command.ip");
        RMI_PORT = config.getInt("port.rmi.rmiPort");
        THREADNUM_LOGIC_SERVER = config.getInt("logicthread.server.value");
        THREADNUM_LOGIC_CLIENT = config.getInt("logicthread.client.value");
        CLASSNAME_PROTOCOLCODEC = config.getString("protocolcodec.class.value");
        PROTOCOL_NAME = config.getString("protocolcodec.name.value");
        PROTOCOL_VERSION = config.getString("protocolcodec.version.value");
        HEARTBEAT = config.getLong("heartbeat.value");
        DOWNLOADPATH = config.getString("downloadpath.value");
        DB_DRIVER = config.getString("db.driver");
        DB_URL = config.getString("db.url");
        USER = config.getString("db.user");
        PASSWD = config.getString("db.passwd");
        DB_INITPOOL_SIZE = config.getInt("db.initpool");
        DB_MAXPOOL_SIZE = config.getInt("db.maxpool");
        CHECK_TIME = Integer.valueOf(config.getString("sys.checktime"));
        GET_SESSION_WAIT = Integer.valueOf(config.getString("sys.getsessionwait"));
        GET_SESSION_WAIT_COUNT = Integer.valueOf(config.getString("sys.getsessionwaitcount"));
        REPLY_WAIT = Integer.valueOf(config.getString("sys.replywait"));
        REPLY_WAIT_COUNT = Integer.valueOf(config.getString("sys.replywaitcount"));
        TIME_OUT = Integer.valueOf(config.getString("sys.timeout"));
    }
}
